<!-- 基础算法弹窗表单模板 -->
<style>
/* 弹窗样式 */
.xc_modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    overflow-y: auto;
}

.xc_modal-overlay.active {
    display: flex;
    animation: xc_fadeIn 0.2s ease;
    align-items: flex-start;
    justify-content: center;
    padding: 20px 0;
}

@keyframes xc_fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.xc_modal-container {
    background: white;
    border-radius: 8px;
    width: 90%;
    max-width: 750px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    animation: xc_slideIn 0.3s ease;
    margin: auto;
    max-height: calc(100vh - 40px);
}

@keyframes xc_slideIn {
    from {
        transform: translateY(-20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.xc_modal-header {
    position: relative;
    padding: 14px 18px;
    border-bottom: 1px solid #e5e7eb;
    background: #fafafa;
    border-radius: 8px 8px 0 0;
    flex-shrink: 0;
}

.xc_modal-title {
    font-size: 16px;
    font-weight: 500;
    color: #374151;
    display: flex;
    align-items: center;
    gap: 8px;
}

.xc_modal-title i {
    color: #3b82f6;
}

.xc_modal-close {
    position: absolute;
    top: 12px;
    right: 16px;
    width: 30px;
    height: 30px;
    border: none;
    background: white;
    color: #6b7280;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    border-radius: 4px;
    border: 1px solid #d1d5db;
    transition: all 0.2s;
}

.xc_modal-close:hover {
    background: #f3f4f6;
    color: #374151;
    border-color: #9ca3af;
}

.xc_modal-body {
    flex: 1;
    padding: 18px 20px;
    overflow-y: auto;
}

.xc_form-row {
    display: flex;
    gap: 14px;
    margin-bottom: 12px;
}

.xc_form-row .xc_form-group {
    flex: 1;
    margin-bottom: 0;
}

.xc_form-group {
    margin-bottom: 12px;
}

.xc_form-label {
    display: block;
    font-size: 13px;
    color: #374151;
    margin-bottom: 6px;
    font-weight: 500;
}

.xc_form-label .required {
    color: #ef4444;
    margin-left: 2px;
}

.xc_form-label .xc_info-icon {
    color: #9ca3af;
    cursor: help;
    margin-left: 4px;
}

.xc_form-input, .xc_form-select, .xc_form-textarea {
    width: 100%;
    padding: 7px 10px;
    font-size: 13px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    background: white;
    color: #374151;
    transition: all 0.2s;
}

.xc_form-input {
    height: 34px;
}

.xc_form-select {
    height: 34px;
}

.xc_form-textarea {
    resize: vertical;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    min-height: 60px;
    line-height: 1.5;
}

.xc_form-input:focus, .xc_form-select:focus, .xc_form-textarea:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
}

.xc_form-input:disabled, .xc_form-select:disabled, .xc_form-textarea:disabled {
    background: #f3f4f6;
    color: #9ca3af;
    cursor: not-allowed;
}

.xc_form-hint {
    font-size: 12px;
    color: #9ca3af;
    margin-top: 4px;
    display: block;
}

.xc_file-input {
    padding: 0 10px;
    font-size: 13px;
    cursor: pointer;
    display: flex;
    align-items: center;
    height: 34px;
    line-height: 34px;
}

.xc_file-input::file-selector-button {
    padding: 5px 12px;
    margin-right: 10px;
    font-size: 12px;
    color: #374151;
    background: #f3f4f6;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    line-height: 1.2;
}

.xc_file-input::file-selector-button:hover {
    background: #e8f4f1;
    border-color: #10b981;
}

.xc_modal-footer {
    padding: 14px 18px;
    border-top: 1px solid #e5e7eb;
    text-align: right;
    background: #fafafa;
    border-radius: 0 0 8px 8px;
    flex-shrink: 0;
}

.xc_modal-btn {
    padding: 7px 18px;
    font-size: 13px;
    border-radius: 4px;
    border: 1px solid #d1d5db;
    cursor: pointer;
    margin-left: 10px;
    transition: all 0.2s;
    font-weight: 400;
    background: white;
    color: #374151;
}

.xc_modal-btn:hover {
    background: #f9fafb;
    border-color: #9ca3af;
}

.xc_modal-btn-primary {
    background: #3b82f6;
    color: white;
    border-color: #3b82f6;
}

.xc_modal-btn-primary:hover {
    background: #2563eb;
    border-color: #2563eb;
}

.xc_modal-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.xc_progress-text {
    font-size: 12px;
    color: #6b7280;
    margin-left: 12px;
}

@media (max-width: 768px) {
    .xc_modal-container {
        width: 95%;
        max-width: none;
    }
    
    .xc_form-row {
        flex-direction: column;
    }
}
</style>

<div class="xc_modal-overlay" id="algorithmModal">
    <div class="xc_modal-container">
        <div class="xc_modal-header">
            <div class="xc_modal-title" id="modalTitle">
                <i class="fa fa-plus-circle"></i>
                添加基础算法
            </div>
            <button class="xc_modal-close" onclick="closeAlgorithmModal()">×</button>
        </div>
        <div class="xc_modal-body">
            <form id="algorithmForm" enctype="multipart/form-data">
                <input type="hidden" id="form_handle" value="add">
                <input type="hidden" id="form_code" value="">
                
                <div class="xc_form-group" id="code_group" style="display: none;">
                    <label class="xc_form-label">算法编号</label>
                    <input type="text" id="input_code_display" class="xc_form-input" disabled>
                </div>
                
                <div class="xc_form-group">
                    <label class="xc_form-label">算法名称<span class="required">*</span></label>
                    <input type="text" id="input_name" class="xc_form-input" placeholder="请输入算法名称">
                </div>
                
                <div class="xc_form-row">
                    <div class="xc_form-group">
                        <label class="xc_form-label">算法类型<span class="required">*</span></label>
                        <select id="input_algorithm_type" class="xc_form-select">
                            <option value="0">请选择</option>
                        </select>
                    </div>
                    <div class="xc_form-group">
                        <label class="xc_form-label">算法框架<span class="required">*</span></label>
                        <select id="input_framework" class="xc_form-select">
                            <option value="0">请先选择算法类型</option>
                        </select>
                    </div>
                </div>
                
                <div class="xc_form-row">
                    <div class="xc_form-group">
                        <label class="xc_form-label">推理引擎<span class="required">*</span></label>
                        <select id="input_inference" class="xc_form-select">
                            <option value="0">请先选择算法类型</option>
                        </select>
                    </div>
                    <div class="xc_form-group">
                        <label class="xc_form-label">
                            推理设备<span class="required">*</span>
                            <i class="fa fa-info-circle xc_info-icon" title="推理引擎设备，比如CPU,GPU,GPU:0,GPU:1"></i>
                        </label>
                        <input type="text" id="input_inference_device" class="xc_form-input" placeholder="CPU">
                    </div>
                </div>
                
                <div class="xc_form-group">
                    <label class="xc_form-label">
                        模型推理参数<span class="required">*</span>
                        <i class="fa fa-info-circle xc_info-icon" title="分析器基于模型计算时的自定义参数"></i>
                    </label>
                    <input type="text" id="input_extend_params" class="xc_form-input" placeholder="width=640,height=640,nms_threshold=0.5,score_threshold=0.5,fp=16">
                </div>
                
                <div class="xc_form-group" id="model_convert_group">
                    <label class="xc_form-label">
                        模型转换参数<span class="required">*</span>
                        <i class="fa fa-info-circle xc_info-icon" title="trtexec在将onnx转换为engine的命令行扩展参数"></i>
                    </label>
                    <input type="text" id="input_model_convert_params" class="xc_form-input" placeholder="--fp16">
                </div>
                
                <div class="xc_form-group" id="model_class_group">
                    <label class="xc_form-label">
                        模型目标<span class="required">*</span>
                        <i class="fa fa-copy xc_copy-icon" onclick="copyModelClassNames()" title="复制模型目标" style="cursor: pointer; color: #3b82f6; margin-left: 6px;"></i>
                    </label>
                    <textarea id="input_model_class_names" class="xc_form-textarea" rows="3" placeholder="请填写模型支持的目标名称，如果多个名称请用英文逗号隔开"></textarea>
                </div>
                
                <!-- 编辑模式下的只读信息（三列布局） -->
                <div class="xc_form-row" id="model_info_row" style="display: none;">
                    <div class="xc_form-group" style="max-width: 100px;">
                        <label class="xc_form-label">模型目标数量</label>
                        <input type="text" id="input_model_class_len" class="xc_form-input" disabled>
                    </div>
                    <div class="xc_form-group">
                        <label class="xc_form-label">模型文件路径</label>
                        <input type="text" id="input_model_path" class="xc_form-input" disabled>
                    </div>
                    <div class="xc_form-group" style="max-width: 100px;">
                        <label class="xc_form-label">模型状态</label>
                        <div id="model_status_display" style="padding: 5px 0; font-size: 12px;"></div>
                    </div>
                </div>
                
                <div class="xc_form-group" id="model_file_group">
                    <label class="xc_form-label">模型文件<span class="required">*</span></label>
                    <input type="file" id="input_model_file" class="xc_form-input xc_file-input" accept=".onnx,.engine,.tar,.om,.rknn">
                    <span class="xc_form-hint">支持的文件格式：.onnx, .engine, .tar, .om, .rknn，最大1000M</span>
                </div>
            </form>
        </div>
        <div class="xc_modal-footer">
            <button class="xc_modal-btn" onclick="closeAlgorithmModal()">取消</button>
            <button class="xc_modal-btn xc_modal-btn-primary" id="submitBtn" onclick="submitAlgorithmForm()">
                <span id="submit_text">提交</span>
            </button>
            <span id="submit_loading" style="display: none; margin-left: 12px; color: #3b82f6; font-size: 12px;">
                <i class="fa fa-spinner fa-spin"></i> 提交中...
            </span>
            <span id="submit_timer" style="display: none; margin-left: 8px; color: #10b981; font-size: 12px; font-weight: 500;"></span>
        </div>
    </div>
</div>
